<%@ page contentType="text/html;charset=UTF-8" language="java"%> <%@include file="/common.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-invoiceApply-edit">
			<input id="iaId" name="iaId" value="${invoiceApply.iaId}" type="hidden">
			<input id="taskId" name="taskId" value="${taskId}" type="hidden">
			<div class="form-group">
				<label class="col-sm-2 control-label">纳税人号码：</label>
				<div class="col-sm-8">
					<input id="iaTaxpayerNum" name="iaTaxpayerNum" value="${invoiceApply.iaTaxpayerNum}" class="form-control" type="text"  ${ not empty taskId ? 'readonly' :''  } >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">纳税人名字：</label>
				<div class="col-sm-8">
					<input id="iaTaxpayerName" name="iaTaxpayerName" value="${invoiceApply.iaTaxpayerName}" class="form-control" type="text" ${ not empty taskId ? 'readonly' :''  }>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">企业税号：</label>
				<div class="col-sm-8">
					<input id="bussinessNum" name="bussinessNum" value="${invoiceApply.bussinessNum}" class="form-control" type="text" ${ not empty taskId ? 'readonly' :''  }>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">购票手折：</label>

				<div class="col-sm-5">
					<!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
					<input type="file" id="addUpload1" onchange="uploadFile('iaGpszPicture','1')" class="form-control" accept="image/*"  ${ not empty taskId ? 'readonly' :''  }  />
					<input type="hidden" id="iaGpszPicture" name="iaGpszPicture" value="${invoiceApply.iaGpszPicture}" />
				</div>
				<div class="col-sm-5">
					<img class="img-rounded" width="100" height="100" id="img1" src="${ctx}/${invoiceApply.iaGpszPicture}" class="img-thumbnail"${ not empty taskId ? 'readonly' :''  } />
				</div>


			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">申请购买发票审批表：</label>
				<div class="col-sm-5">
					<!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
					<input type="file" id="addUpload2" onchange="uploadFile('iaFpshPicture','2')" class="form-control" accept="image/*" ${ not empty taskId ? 'readonly' :''  }/>
					<input type="hidden" id="iaFpshPicture" name="iaFpshPicture" value="${invoiceApply.iaFpshPicture}" />
				</div>
				<div class="col-sm-5">
					<img class="img-rounded" width="100" height="100" id="img2" src="${ctx}/${invoiceApply.iaFpshPicture}" class="img-thumbnail" />
				</div>

			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">ic卡：</label>
				<div class="col-sm-5">
					<!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
					<input type="file" id="addUpload3" onchange="uploadFile('iaIcCardPicture','3')" class="form-control" accept="image/*" ${ not empty taskId ? 'readonly' :''  }/>
					<input type="hidden" id="iaIcCardPicture" name="iaIcCardPicture" value="${invoiceApply.iaIcCardPicture}" />
				</div>
				<div class="col-sm-5">
					<img class="img-rounded" width="100" height="100" id="img3" src="${ctx}/${invoiceApply.iaIcCardPicture}" class="img-thumbnail" />
				</div>

			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类型：</label>
				<div class="col-sm-8">
					<select id="iaType" name="iaType" class="form-control" type="text" ${ not empty taskId ? 'readonly' :''  }>
						<option value="1" ${invoiceApply.iaType==1?'selected':''}>一般发票</option>
						<option value="2" ${invoiceApply.iaType==2?'selected':''}>增值税专用发票</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">数量：</label>
				<div class="col-sm-8">
					<input id="iaCount" name="iaCount" value="${invoiceApply.iaCount}" class="form-control" type="number"  />
				</div>
			</div>
			<c:if test="${ not empty taskId}">
				<div class="form-group">
					<label class="col-sm-3 control-label">&nbsp;</label>
					<div class="col-sm-8">
						<a class="btn btn-primary btn-del" onclick="submitHandler()">
							<i class="fa fa-play"></i>
							确定
						</a>
					</div>
				</div>
			</c:if>
			
		</form>
	</div> 
	<script type="text/javascript">
		var prefix =  "${ctx}/system/apply";
		$("#form-invoiceApply-edit").validate({
			rules : {
			iaTaxpayerName : {
					required : true,
					minlength : 2,
					maxlength : 20,
				},
				iaTaxpayerNum : {
					required : true,
					minlength : 2,
					maxlength : 20,
				},
				iaCount : {
					required : true,
					range : [ 1, 10000 ]
				},
				bussinessNum : {
					required : true,
					minlength : 2,
					maxlength : 20,
				},
			}
		});
	
		function submitHandler() {
            if (!$("#iaFpshPicture").val() || !$("#iaIcCardPicture").val() || !$("#iaGpszPicture").val()) {
                alert("请上传完整的图片");
                return;
            }
			if ($.validate.form()) {
				$.operate.save(prefix + "/edit", $('#form-invoiceApply-edit').serialize());
			}
		}



        function uploadFile(type, sort) {
            var formData = new FormData();
            formData.append("upload", $("#addUpload" + sort)[0].files[0]); //第一个file1代表后台文件属性名，第二个file1表示html中input的id
            $.ajax({
                type : "post",
                url : "${ctx}/file/upload",
                data : formData,
                processData : false,
                contentType : false,
                dataType : 'json',
                success : function(data) {
                    if (data.code == 0) {
                        $("#" + type).val(data.data.path);
                        $("#img" + sort).attr("src", "${ctx }/" + data.data.path);
                    }
                },
                error : function(msg) {
                    alert(msg.responsText);
                }
            });
        }
	</script>
</body>
</html>
